package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GxMaterialData;
import com.ruoyi.system.service.IGxMaterialDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 患教资料管理Controller
 * 
 * @author ruoyi
 * @date 2023-05-15
 */
@RestController
@RequestMapping("/system/material")
public class GxMaterialDataController extends BaseController
{
    @Autowired
    private IGxMaterialDataService gxMaterialDataService;

    /**
     * 查询患教资料管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(GxMaterialData gxMaterialData)
    {
        startPage();
        List<GxMaterialData> list = gxMaterialDataService.selectGxMaterialDataList(gxMaterialData);
        return getDataTable(list);
    }

    /**
     * 展示患教资料列表
     */
//    @PreAuthorize("@ss.hasPermi('system:material:showMaterial')")
    @GetMapping("/showMaterial")
    public AjaxResult showMaterial(GxMaterialData gxMaterialData)
    {
//        startPage();
        List<GxMaterialData> list = gxMaterialDataService.selectGxMaterialDataList(gxMaterialData);
        return AjaxResult.success(list);
    }

    /**
     * 导出患教资料管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:material:export')")
    @Log(title = "患教资料管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxMaterialData gxMaterialData)
    {
        List<GxMaterialData> list = gxMaterialDataService.selectGxMaterialDataList(gxMaterialData);
        ExcelUtil<GxMaterialData> util = new ExcelUtil<GxMaterialData>(GxMaterialData.class);
        util.exportExcel(response, list, "患教资料管理数据");
    }

    /**
     * 获取患教资料管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:material:query')")
    @GetMapping(value = "/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") Long materialId)
    {
        return AjaxResult.success(gxMaterialDataService.selectGxMaterialDataByMaterialId(materialId));
    }

    /**
     * 新增患教资料管理
     */
    @PreAuthorize("@ss.hasPermi('system:material:add')")
    @Log(title = "患教资料管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxMaterialData gxMaterialData)
    {
        return toAjax(gxMaterialDataService.insertGxMaterialData(gxMaterialData));
    }

    /**
     * 修改患教资料管理
     */
    @PreAuthorize("@ss.hasPermi('system:material:edit')")
    @Log(title = "患教资料管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxMaterialData gxMaterialData)
    {
        return toAjax(gxMaterialDataService.updateGxMaterialData(gxMaterialData));
    }

    /**
     * 删除患教资料管理
     */
    @PreAuthorize("@ss.hasPermi('system:material:remove')")
    @Log(title = "患教资料管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialIds}")
    public AjaxResult remove(@PathVariable Long[] materialIds)
    {
        return toAjax(gxMaterialDataService.deleteGxMaterialDataByMaterialIds(materialIds));
    }
}
